<template>
<div
  class="switch-box"
  :class="{
    active: value,
    default: type === 'default',
    with_icon: type === 'with_icon',
    small: type === 'small'
  }"
  @click="sw">
  <div class="active_icon"></div>
  <div class="switcher"></div>
  <div class="disable_icon"></div>
</div>
</template>

<script>
export default {
  name: 'Switcher',
  props: ['value', 'type'],
  data() {
    return {
      isActive: this.value ? this.value : false,
    };
  },
  methods: {
    sw() {
      this.isActive = !this.isActive;
      this.$emit('input', this.isActive);
      this.$emit('change', this.isActive);
    },
  },
};
</script>

<style lang="less">
@import url(../../../static/style/site.vars.less);
.switch-box {
  position: relative;
  display: inline-block;
  width: 53px;
  height: 25px;
  border-radius: 15px;
  background: rgba(184, 134, 134, 0.3);
  cursor: pointer;
  transition: background-color linear .1s;
  padding: 2px;
  box-sizing: border-box;
  .switcher {
    position: relative;
    left: 0;
    background: #fff;
    border-radius: 30px;
    transition: left linear .1s;
  }
  &.default {
    .switcher {
      width: 21px;
      height: 21px;
    }
    &.active {
      background: @site-main;
      .switcher {
        left: 28px;
        //z-index: 2;
      }
    }
  }
  &.with_icon {
    width: 70px;
    height: 30px;
    .switcher {
      width: 22px;
      height: 22px;
      top: 2px;
      left: 3px;
    }
    &.active {
      background: @site-main;
      .switcher {
        left: 42px;
        z-index: 2;
      }
    }
    .active_icon {
      background: url(../../assets/img/u3388.png);
      width: 17px;
      height: 13px;
      position: absolute;
      z-index: 1;
      left: 9px;
      top: 8px;
    }
    .disable_icon {
      background: url(../../assets/img/u3392.png);
      width: 13px;
      height: 13px;
      position: absolute;
      z-index: 1;
      right: 12px;
      top: 8px;
    }
  }
  &.small {
    width: 35px;
    height: 15px;
    .switcher {
      width: 11px;
      height: 11px;
    }
    &.active {
      background: @site-main;
      .switcher {
        left: 20px;
      }
    }
  }
}
</style>
